<div class="modal-dialog">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
            <h4 class="modal-title">文件借阅</h4>
        </div>
        <div class="modal-body">
            <form class="modalForm form-horizontal" action="{:url('index/Borrows/addFile')}" method="post">
                <div class="form-body">
                    <div class="form-group">
                        <label class="col-md-3 control-label">借阅文件</label>
                        <div class="col-md-9">
                            <input type="text" readonly class="form-control guidf" placeholder="请输入文件夹名称">
                            <input type="hidden" name="arc_id" class="arc_id">
                            <span class="help-block">选择待归档的文件</span>

                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-3 control-label">借阅期限</label>
                        <div class="col-md-9">
                            <input name="bor_time_limit" type="date" class="form-control bor_time_limit">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-3 control-label">借阅方式</label>
                        <div class="col-md-9">
                            <select name="bor_type" class="form-control">
                                <option value="1">在线查看</option>
                                <option value="2">有水印打印</option>
                                <option value="3">无水印打印</option>
                                <option value="4">下载PDF版</option>
                                <option value="5">下载原始文件</option>
                                <option value="6">查看原件</option>
                                <option value="7">借用复印件</option>
                                <option value="8">领用复印件</option>
                                <option value="9">借用原件</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-3 control-label">借阅份数</label>
                        <div class="col-md-9">
                            <input name="bor_num" type="text" class="form-control">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-md-3 control-label">描述</label>
                        <div class="col-md-9">
                            <textarea name="bor_desc" class="form-control"></textarea>
                        </div>
                    </div>
                </div>
            </form>
        </div>
        <div class="modal-footer">
            <button type="button" class="btn default model1close" data-dismiss="modal">关闭</button>
            <button type="button" class="btn blue save">保存</button>
        </div>
    </div>
</div>


<div class="modal fade" id="model2" tabindex="-1" role="model2" aria-hidden="true" style="display: none;">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close closeBtn" ></button>
                <h4 class="modal-title">选择文件</h4>
            </div>
            <div class="navbar navbar-default" role="navigation" style="margin-bottom:0">
                <div class="collapse navbar-collapse navbar-ex1-collapse">
                    <ul class="nav navbar-nav">
                        <li class="active tags" data-id="1">
                            <a href="#" >
                                预归档
                            </a>
                        </li>
                        <li class="tags" data-id="2">
                            <a href="#" >
                                档案库
                            </a>
                        </li>
                        <li class="tags" data-id="3">
                            <a href="#" >
                                编研库
                            </a>
                        </li>
                    </ul>
                </div>
            </div>
            <div class="modal-body">
                <div class="portlet green box ">
                    <div class="portlet-title">
                        <div class="caption">
                            <i class="fa fa-cogs"></i>目录
                        </div>
                    </div>
                    <div class="portlet-body showTree">
                        <div id="tree_5" class="tree-demo" >
                            {$tree}
                        </div>
                    </div>
                </div>
                <div class="portlet-body  ">
                    <div class="table-responsive">
                        <table class="table table-striped table-bordered table-advance table-hover  ">
                            <thead>
                            <tr>
                                <th>
                                    <i class="fa fa-tags"></i> 文件名
                                </th>
                                <th class="hidden-xs">
                                    <i class="fa fa-tag"></i> 创建者
                                </th>
                                <th>
                                    <i class="fa fa-tag"></i> 大小
                                </th>
                                <th>
                                    设置
                                </th>
                            </tr>
                            </thead>
                            <tbody class="tbody" style="text-align: center">

                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<script>
    // App.init();
    // UITree.init();
    upTree('tree_5');
    $('.closeBtn').click(function () {
        $('#model2').modal('hide');
        $('#model3').modal('hide');
        return false;
    });
    $('.guidf').click(function () {
        $('#model2').modal('show');
    });
    $('.guidp').click(function () {
        $('#model3').modal('show');
    });
    var cid;
    $('.navbar-nav li').click(function () {
        var $this = $(this);
        var id = $this.attr('data-id');

        if(id == 1){cid = -1}
        else if(id == 2){cid = -2}
        else{cid = -3}
        console.log(cid);
        $.ajax({
            url:'{:url(\'index/Borrows/getTree\')}',
            data:{cate_type:id},
            dataType:'json',
            type:'post',
            success:function (e) {
                if(e.code == 1) {
                    $('.showTree').html('<div id="tree_4" class="tree-demo" >'+e.data+'</div>');
                    getArc(cid);
                }else{
                    $('.showTree').html('<div id="tree_4" class="tree-demo" >'+e.msg+'</div>');
                }
                $('.navbar-nav li').removeClass('active');
                $this.addClass('active');
                setTimeout(function () {
                    upTree('tree_4');
                    $("#tree_4").on('changed.jstree', function (e, data) {
                        var id = data.node.data.id;
                        getArc(id);

                    });
                },100);
            }
        });
    });
    //进来 预归档根目录文件
    getArc(-1);
    $('.bor_time_limit').val('{$date}');
    $("#tree_5").on('changed.jstree', function (e, data) {
        var id = data.node.data.id;
        getArc(id);

    });

    $("#tree_1").on('changed.jstree', function (e, data) {
        var id = data.node.data.id;
        $.ajax({
            url:'{:url(\'index/File/getPathById\')}',
            data:{id:id},
            dataType:'json',
            type:'post',
            success:function (e) {
                $('.interfile_cate_id').val(id);
                $('.guidp').val(e.data);
                $('#model3').modal('hide');
            }
        });


    });
    function getArc(id) {
        $.ajax({
            url:'{:url(\'index/File/getArcByCateId\')}',
            data:{id:id},
            dataType:'json',
            type:'post',
            success:function (e) {
                if(e.code == 1) {
                    $('.tbody').html(e.data);
                    $('.editBtn').click(function () {
                        var aid = $(this).attr('data-id');
                        var aname = $(this).attr('data-name');
                        $('.guidf').val(aname);
                        $('.arc_id').val(aid);
                        $('#model2').modal('hide');
                    });
                }else{
                    $('.tbody').html('');
                }
            }
        });
    }
    
    function upTree(id) {
        $('#'+id).jstree({
            "core" : {
                "themes" : {
                    "responsive": false
                }
            },
            "types" : {
                "default" : {
                    "icon" : "fa fa-folder icon-warning icon-lg"
                },
                "file" : {
                    "icon" : "fa fa-file icon-warning icon-lg"
                }
            },
            "plugins": ["types"]
        });
    }
    dt().modalSave();
</script>